﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

public class tblHotline
{

    SqlConnection conn;
    SqlCommand cmd;
	public tblHotline()
	{
        conn = new SqlConnection("server=localhost ; database = OnlineBooking;uid = sa ; pwd=12345678");
	}

    public DataTable getAllHotline() {

        if (conn.State == ConnectionState.Closed)
            conn.Open();
        string sql = "select * from Hotline";
        cmd = new SqlCommand(sql, conn);
        DataTable table = new DataTable();
        SqlDataAdapter data = new SqlDataAdapter(cmd);
        data.Fill(table);
        conn.Close();
        return table;
    
    }

    public DataTable getAllHotlineById(int id)
    {

        if (conn.State == ConnectionState.Closed)
            conn.Open();
        string sql = "select * from Hotline where HotlineID=@id";
        cmd = new SqlCommand(sql, conn);
        cmd.Parameters.AddWithValue("@id",id);
        DataTable table = new DataTable();
        SqlDataAdapter data = new SqlDataAdapter(cmd);
        data.Fill(table);
        conn.Close();
        return table;

    }

    public DataTable deleteHotline(int id)
    {

        if (conn.State == ConnectionState.Closed)
            conn.Open();
        string sql = "delete from Hotline where HotlineID=@id";
        cmd = new SqlCommand(sql, conn);
        cmd.Parameters.AddWithValue("id",id);
        DataTable table = new DataTable();
        SqlDataAdapter data = new SqlDataAdapter(cmd);
        data.Fill(table);
        conn.Close();
        return table;

    }

    public bool AddHotline(string name , string phone , string yahoo , string skype,string des)
    {
        if (conn.State == ConnectionState.Closed)
            conn.Open();
        string sql = "insert into Hotline values (@name,@phone,@yahoo,@skype,@des)";
        cmd = new SqlCommand(sql, conn);
        cmd.Parameters.AddWithValue("@name", name);
        cmd.Parameters.AddWithValue("@phone", phone);
        cmd.Parameters.AddWithValue("@yahoo", yahoo);
        cmd.Parameters.AddWithValue("@skype", skype);
        cmd.Parameters.AddWithValue("@des", des);
        int n = cmd.ExecuteNonQuery();
        bool result = (n > 0);
        conn.Close();
        return result;
    }
    public bool editHotline(string name, string phone, string yahoo, string skype, string des,int id)
    {
        if (conn.State == ConnectionState.Closed)
            conn.Open();
        string sql = "update Hotline set HotlineName=@name,HotlinePhone=@phone,HotlineYahoo=@yahoo,HotlineSkype=@skype,Description=@des where HotlineID=@id";
        cmd = new SqlCommand(sql, conn);
        cmd.Parameters.AddWithValue("@name", name);
        cmd.Parameters.AddWithValue("@phone", phone);
        cmd.Parameters.AddWithValue("@yahoo", yahoo);
        cmd.Parameters.AddWithValue("@skype", skype);
        cmd.Parameters.AddWithValue("@des", des);
        cmd.Parameters.AddWithValue("@id", id);
        int n = cmd.ExecuteNonQuery();
        bool result = (n > 0);
        conn.Close();
        return result;
    }
}